#include "mtime.h"
#include "qkeymetro.h"
using namespace QKeyMetro;


int MTime::getRawValue(int b, int sb)
{
    return (b * RESOLUTION + sb);
}

MTime::MTime(int b, int sb): PoolableObject(PoolableObject::MTIME), value_(getRawValue(b,sb))
{
}

MTime::MTime(int rawValue): PoolableObject(PoolableObject::MTIME), value_(rawValue)
{
}

MTime::MTime(): PoolableObject(PoolableObject::MTIME), value_(0)
{
}

int MTime::getBeats()
{
    return (value_ / RESOLUTION);
}

int MTime::getBeats(int rawValue)
{
    return (rawValue / RESOLUTION);
}

int MTime::getSubBeats() // RESOLUTION subbeats in one beat
{
    return (value_ / RESOLUTION);
}

int MTime::getSubBeats(int rawValue)
{
    return (rawValue % RESOLUTION);
}

int MTime::getRawValue()// = RESOLUTION * beats + subbits; so it's 7 hours for 120 bpm
{
    return value_;
}

void MTime::operator=(int rawValue)
{
    value_=rawValue;
}

void MTime::setValue(int b, int sb)
{
    value_=(b * RESOLUTION + sb);
}

